package hs.framework.opcClient.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import hs.framework.opcClient.entity.ApiLog;
import hs.framework.opcClient.framework.util.Condition;
import hs.framework.opcClient.framework.util.Func;
import hs.framework.opcClient.framework.util.Query;
import hs.framework.opcClient.framework.util.R;
import hs.framework.opcClient.service.IApiLogService;
import hs.framework.opcClient.wrapper.ApiLogWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Description TODO
 * @Author sxmz
 * @Date 2021/5/17 0017 上午 11:37
 */
@RestController
@AllArgsConstructor
@RequestMapping("/apiLog")
@Api(value = "接口日志表,用于记录接口日志", tags = "接口日志表,用于记录接口日志")
public class ApiLogController {

    private IApiLogService apiLogService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入apiLog")
    public R<ApiLog> detail(ApiLog apiLog) {
        ApiLog detail = apiLogService.getOne(Condition.getQueryWrapper(apiLog));
        return R.data(ApiLogWrapper.build().entityVO(detail));
    }

    /**
     * 分页 数据源信息表,用于对接控制数据
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入apiLog")
    public R<IPage<ApiLog>> list(ApiLog apiLog, Query query) {
        IPage<ApiLog> pages = apiLogService.page(Condition.getPage(query), Condition.getQueryWrapper(apiLog));
        return R.data(ApiLogWrapper.build().pageVO(pages));
    }
    /**
     * 自定义分页 数据源信息表,用于对接控制数据
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入apiLog")
    public R<IPage<ApiLog>> page(ApiLog apiLog, Query query) {
        IPage<ApiLog> pages = apiLogService.selectApiLogPage(Condition.getPage(query), apiLog);
        return R.data(pages);
    }

    /**
     * 新增 数据源信息表,用于对接控制数据
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入apiLog")
    public R save(@Valid @RequestBody ApiLog apiLog) {
        Boolean flag = apiLogService.save(apiLog);
        return R.status(flag);
    }

    /**
     * 修改 数据源信息表,用于对接控制数据
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入apiLog")
    public R update(@Valid @RequestBody ApiLog apiLog) {
        Boolean flag = apiLogService.updateById(apiLog);
        return R.status(flag);
    }

    /**
     * 新增或修改 数据源信息表,用于对接控制数据
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入apiLog")
    public R submit(@Valid @RequestBody ApiLog apiLog) {
        Boolean flag = apiLogService.saveOrUpdate(apiLog);
        return R.status(flag);
    }


    /**
     * 删除 数据源信息表,用于对接控制数据
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        Boolean flag = apiLogService.removeByIds(Func.toLongList(ids));
        return R.status(flag);
    }
}
